<style>
    .xxpayPopupDiv .layui-form-label {
        width:120px !important;
        margin-left:1%;
    }
    .xxpayPopupDiv .layui-input-inline {
        width: 80% !important;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <div class="layui-tab-content">
                <form class="layui-form center">
                    <input type="hidden" name="id" id="id">
                    <div class="layui-form-item">
                        <label class="layui-form-label">通道名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="passageName" id="passageName" placeholder="请输入通道名称" required lay-verify="required"  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">手续费类型</label>
                        <div class="layui-input-inline" >
                            <input type="radio" name="feeType" value="1" title="百分比收费" lay-filter="feeTypeFilter">
                            <input type="radio" name="feeType" value="2" title="固定收费" lay-filter="feeTypeFilter">
                            <input type="radio" name="feeType" value="3" title="百分比收费+固定收费" lay-filter="feeTypeFilter">
                        </div>
                    </div>
                    <div class="layui-form-item" id="feeRateId" style="display: none">
                        <label class="layui-form-label">手续费费率(%)</label>
                        <div class="layui-input-inline">
                            <input type="tel" id="feeRate" name="feeRate" placeholder="输入手续费费率" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item" id="feeEveryId" style="display: none">
                        <label class="layui-form-label">每笔手续费(元)</label>
                        <div class="layui-input-inline">
                            <input type="tel" id="feeEvery" name="feeEvery" placeholder="输入每笔手续费" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-inline">
                            <button type="button" class="layui-hide xxpayYesBtn" lay-submit="" lay-filter="update">保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>

    layui.use(['form','table','util','admin'],function(){
        var form = layui.form
                , $ = layui.$
                , admin = layui.admin
                , layer = layui.layer
                , element = layui.element
                , view = layui.view
                , table = layui.table;

        element.render('breadcrumb', 'breadcrumb'); //渲染导航信息

        var id = view.getOpenParams('id');
        admin.req({
            type: 'post',
            url: layui.setter.baseUrl + '/config/agentpay_passage/get',
            data: {
                id:id,
            },
            error: function(err){
                layer.alert(err);
            },
            success: function(res){
                if(res.code == 0){
                    $('#id').val(res.data.id);
                    $('#passageName').val(res.data.passageName);
                    $('#feeRate').val(res.data.feeRate);
                    $('#feeEvery').val(res.data.feeEvery/100);
                    if(res.data.feeType == 1) {
                        $("input[name='feeType'][value='1']").attr("checked",true);
                        $("#feeRateId").show();
                        $("#feeEveryId").hide();
                    }else if(res.data.feeType == 2) {
                        $("input[name='feeType'][value='2']").attr("checked",true);
                        $("#feeRateId").hide();
                        $("#feeEveryId").show();
                    }else if(res.data.feeType == 3) {
                        $("input[name='feeType'][value='3']").attr("checked",true);
                        $("#feeRateId").show();
                        $("#feeEveryId").show();
                    }
                    form.render();
                }
            }
        });

        form.on('submit(update)', function(data){
            admin.req({
                type: 'post',
                url: layui.setter.baseUrl + '/config/agentpay_passage/rate_update', //,
                data: data.field,
                error: function(err){layer.alert(err.msg,{title:"请求失败"})},
                success: function(res){
                    if(res.code == 0){
                        layer.alert(res.msg, {title: '保存成功'},function(index){
                            layer.closeAll(); //关闭所有弹层
                            layui.table.reload('tableReload'); //调用业务弹层外表格重新加载
                        });
                    }
                }
            });
            return false;
        });

        form.on('radio(feeTypeFilter)', function(data){
            if(data.value == 1) {
                $("#feeRateId").show();
                $("#feeEveryId").hide();
            }else if(data.value == 2) {
                $("#feeRateId").hide();
                $("#feeEveryId").show();
            }else if(data.value == 3) {
                $("#feeRateId").show();
                $("#feeEveryId").show();
            }
        });

    });

</script>
